﻿using System.Collections.Generic;
using Renren.Models;
using System;
using Renren.Services;

namespace Renren.ViewModels
{
    public class PlaceViewModel : ViewModel<PlaceModel>
    {
        public PlaceViewModel() : base() { }
        public PlaceViewModel(PlaceModel place) : base(place) { }

        public string Distance
        {
            get
            {
                double R = 6371;
                double lat1 = Model.Geometry.Location.Latitude * Math.PI / 180;
                double lng1 = Model.Geometry.Location.Longitude * Math.PI / 180;
                double lat2 = PlaceService.GeoWatcher.Position.Location.Latitude * Math.PI / 180;
                double lng2 = PlaceService.GeoWatcher.Position.Location.Longitude * Math.PI / 180;
                var distance = Math.Acos(Math.Sin(lat1) * Math.Sin(lat2) +
                                         Math.Cos(lat1) * Math.Cos(lat2) *
                                         Math.Cos(lng2 - lng1)) * R;
                if (distance < 1)
                {
                    return (int)(distance * 1000) + "米";
                }
                else
                {
                    return distance.ToString("F2") + "公里";
                }
            }
        }

        public string Types
        {
            get
            {
                return string.Join(", ", Model.Types);
            }
        }

        protected override List<string> PropertyNames
        {
            get
            {
                return new List<string>
                {
                    "Distance",
                    "Types"
                };
            }
        }
    }
}
